<!--
@description: 员工管理
@creationTime: 2025-04-14
-->

<route type="page" lang="json5">
{
  layout: 'default',
  style: {
    navigationBarTitleText: '用户管理'
  }
}
</route>

<template>
  <view class="bg-#fff pos-fixed pos-top-none w-100vw z-10">
    <wd-row>
      <wd-col :span="20">
        <wd-search placeholder="请输入查询条件" :hide-cancel="true" v-model="searchValue" @search="search" />
      </wd-col>
      <wd-col :span="4">
        <!-- 修改为原生button并添加open-type -->

        <view class="flex flex-items-center pt-3">
          <wd-button type="text" size="small" icon="share" open-type="share">邀请</wd-button>
        </view>
      </wd-col>
    </wd-row>
  </view>
  <view class="pt-14"></view>
  <scroll-view class="h-84vh" scroll-y>
    <StaffCard v-for="(item, index) in staffList" :key="index" :user="item" @edit="search"></StaffCard>
  </scroll-view>

  <view class="pos-fixed bottom-6 left-0 w-100vw px-3 box-border!">
    <wd-button :block="true" icon="add" @click="share">添加用户</wd-button>
  </view>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import StaffCard from './components/StaffCard.vue'
import { queryUserInfoByTypeApi } from '@/api/userInfoByType'
const staffList = ref([])
const searchValue = ref('')
const type = ref('')
onShow(async () => {
  search()
})
onLoad(res => {
  type.value = res.type
  wx.showShareMenu({
    withShareTicket: true,
    menus: ['shareAppMessage', 'shareTimeline']
  })
})
const search = () => {
  uni.showLoading({ title: '加载中...', mask: true })
  queryUserInfoByTypeApi({ userType: type.value, keyName: searchValue.value }).then((res: any) => {
    uni.hideLoading()
    staffList.value = res.data
  })
}
const share = () => {
  uni.navigateTo({ url: '/pages/my/addUsers/index?type=' + type.value })
}
</script>
<script lang="ts">
import { useUserStore } from '@/store'
export default {
  data() {
    return {
      type: ''
    }
  },
  onLoad(options) {
    this.type = options.type
  },
  onShareAppMessage() {
    const userStore = useUserStore()
    return {
      title: '邀请你加入我们的团队',
      path: `/pages/my/share/index?type=${this.type}&id=` + userStore.userInfo.id
    }
  }
}
</script>

<style lang="scss" scoped></style>
